package loads

import (
	"jvm/instructions/base"
	"jvm/rtda"
)

// ILOAD Load int from local variable
type ILOAD struct{ base.Index8Instruction }

func (il *ILOAD) Execute(jFrame *rtda.JFrame) {
	_iload(jFrame, il.Index)
}

type ILOAD_0 struct{ base.NoOperandsInstruction }

func (il *ILOAD_0) Execute(jFrame *rtda.JFrame) {
	_iload(jFrame, 0)
}

type ILOAD_1 struct{ base.NoOperandsInstruction }

func (il *ILOAD_1) Execute(jFrame *rtda.JFrame) {
	_iload(jFrame, 1)
}

type ILOAD_2 struct{ base.NoOperandsInstruction }

func (il *ILOAD_2) Execute(jFrame *rtda.JFrame) {
	_iload(jFrame, 2)
}

type ILOAD_3 struct{ base.NoOperandsInstruction }

func (il *ILOAD_3) Execute(jFrame *rtda.JFrame) {
	_iload(jFrame, 3)
}

func _iload(jFrame *rtda.JFrame, index uint) {
	val := jFrame.LocalVars().GetInt(index)
	jFrame.OperandStack().PushInt(val)
}
